#$Id: Makefile.1,v 1.49.4.1 2001/01/08 08:11:13 guenther Exp $

all: bins mans recommend
	@echo If you would like to inspect the results before running make \
install:
	@echo All installable files can be found in the new/ subdirectory.

make:
	@$(SHELL) -c "exit 0"

.PRECIOUS: Makefile

help target targets:
	@sed "/^##*\*#$$/,/^##*\*#$$/ !d" <Makefile

bins: autoconf.h config.check src/Makefile
	cd src; $(MAKE) $(NBINS)

mans: autoconf.h config.check man/Makefile
	cd man; $(MAKE) $(NMANS)

autoconf.h: src/Makefile src/autoconf
	cd src; $(MAKE) ../$@

procmail: autoconf.h config.check src/Makefile man/Makefile
	cd src; $(MAKE) ../new/$@ ../new/mailstat
	cd man; $(MAKE) ../new/$@.1 ../new/$@rc.5 ../new/$@ex.5 ../new/$@sc.5

mailstat: procmail

formail lockfile: autoconf.h config.check src/Makefile man/Makefile
	cd src; $(MAKE) ../new/$@
	cd man; $(MAKE) ../new/$@.1

setid multigram: autoconf.h config.check src/Makefile man/Makefile
	cd src; $(MAKE) $@

config.check: config.h
	echo Housekeeping file >$@
	-mkdir new 2>$(DEVNULL); exit 0
	@-if $(FGREP) -n -e '`' config.h $(DEVNULL) | $(FGREP) -v EOFName ; \
 then \
 echo;echo '   ^^^^^^^^^^^^^^^^^^^^ WARNING ^^^^^^^^^^^^^^^^^^^^^';\
      echo '   * Having backquotes in there could be unhealthy! *';\
 echo;fi;exit 0

recommend: autoconf.h src/Makefile
	@cd src; $(MAKE) $@
	@echo ================================================================\
===============
	@if $(FGREP) CF_no_procmail_yet autoconf.h >$(DEVNULL); \
 then echo If you are a system administrator you should consider \
integrating procmail; echo into the mail-delivery system -- for advanced \
functionality, speed AND; echo SECURITY "--.  For" more information about \
this topic you should look in the; echo examples/advanced file.; elif \
 cat /usr/lib/sendmail.cf /etc/sendmail.cf 2>$(DEVNULL) | \
 grep 'Mlocal.*procmail.*F=[a-zA-Z]*u' >$(DEVNULL) ; then \
 echo The recommendation for the sendmail.cf entry of procmail has \
changed.; echo I suggest you remove the '`u'"'"-flag 'like in:'; echo ; \
 sed -n 's/.*\(Mlocal.*procmail.*F=[a-zA-Z]*\)u/\1/p' `if test -f \
 /etc/sendmail.cf; then echo /etc/sendmail.cf; else \
 echo /usr/lib/sendmail.cf; fi`; fi
	@echo
	@echo \
 "Also, HIGHLY RECOMMENDED (type 'make install-suid' to execute it):"
	@echo
	@src/$@ $(BINDIR)/procmail $(BINDIR)/lockfile >suid.sh
	@src/$@ $(BINDIR)/procmail $(BINDIR)/lockfile
	@echo ================================================================\
===============

suid.sh: recommend

install-suid: suid.sh install.bin
	@cat suid.sh
	@$(SHELL) ./suid.sh
	@cd $(BINDIR); echo Installed in $(BINDIR); ls -l $(BINSS)

$(MANS): mans

$(BINS): bins

$(BASENAME):
	mkdir $(BASENAME)

install.man: $(MANS) $(BASENAME)
	@-mkdir $(MANDIR) 2>$(DEVNULL); exit 0
	@-test -d $(MAN1DIR) || $(RM) $(MAN1DIR); exit 0
	@-mkdir $(MAN1DIR) 2>$(DEVNULL); exit 0
	@-test -d $(MAN5DIR) || $(RM) $(MAN5DIR); exit 0
	@-mkdir $(MAN5DIR) 2>$(DEVNULL); exit 0
	@chmod 0644 $(MANS)
	@for a in $(MANS1S); \
  do $(INSTALL) new/$$a.1 $(MAN1DIR)/$$a.$(MAN1SUFFIX) || exit 1; \
     if test "X$(MANCOMPRESS)" != "X"; \
     then $(MANCOMPRESS) -c new/$$a.1 >$(MAN1DIR)/$$a.$(MAN1SUFFIX); \
     else :; fi; \
  done
	@for a in $(MANS5S); \
  do $(INSTALL) new/$$a.5 $(MAN5DIR)/$$a.$(MAN5SUFFIX) || exit 1; \
     if test "X$(MANCOMPRESS)" != "X"; \
     then $(MANCOMPRESS) -c new/$$a.5 >$(MAN5DIR)/$$a.$(MAN5SUFFIX); \
     else :; fi; \
  done
	echo Housekeeping file >install.man

install.bin: $(BINS) $(BASENAME)
	@-mkdir $(BINDIR) 2>$(DEVNULL); exit 0
	@chmod 0755 $(BINS)
	$(INSTALL) $(BINS) $(BINDIR)
	@-dirname / >$(DEVNULL) || $(INSTALL) examples/dirname $(BINDIR)
	echo Housekeeping file >install.bin

install:
	@$(MAKE) install.man install.bin
	@echo
	@cd $(BINDIR); echo Installed in $(BINDIR); ls -l $(BINSS)
	@cd $(MAN1DIR); echo Installed in $(MAN1DIR); ls -l $(MANS1)
	@cd $(MAN5DIR); echo Installed in $(MAN5DIR); ls -l $(MANS5)
	@$(MAKE) recommend

deinstall:
	@echo ============================= Deinstalling the procmail package.
	@$(RM) install.man install.bin
	@echo ============================= Checking if everything was removed:
	@-cd $(BINDIR); $(RM) $(BINSS); ls -l $(BINSS); exit 0
	@-cd $(MAN1DIR); $(RM) $(MANS1); ls -l $(MANS1); exit 0
	@-cd $(MAN5DIR); $(RM) $(MANS5); ls -l $(MANS5); exit 0
	@echo ============================= Ready.

clean: config.check
	-for a in $(SUBDIRS); do cd $$a; $(MAKE) $@; cd ..; done; exit 0
	cd SmartList; $(RM) targetdir.h targetdir.tmp install.list asked.patch
	$(RM) $(MANS) $(BINS) install.man install.bin suid.sh _Makefile \
 *core* autoconf.h.tmp

realclean: clean _init
	$(RM) config.check
	-rmdir new; exit 0
	-for a in $(SUBDIRS); do $(MV) $$a/Makefile.init $$a/Makefile; done; \
 exit 0

veryclean clobber: realclean

_init:
	sed -e '/^# Makefile.1 - mark/,$$ d' <Makefile >_Makefile
	cat Makefile.0 >>_Makefile
	$(MV) _Makefile Makefile
	$(RM) Makefile.0

man/Makefile: man/Makefile.0 Makefile

src/Makefile: src/Makefile.0 Makefile

HIDEMAKE=$(MAKE)

man/Makefile src/Makefile Makefile: Makefile.1 initmake
	sed -e '/^# Makefile.1 - mark/,$$ d' <Makefile >_Makefile
	cat Makefile.0 >>_Makefile
	$(MV) _Makefile Makefile
	$(RM) Makefile.0
	$(HIDEMAKE) init

init makefiles Makefiles makefile: man/Makefile src/Makefile
